home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18410 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: Bradd W. Szonye <bradds@ix.netcom.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: RE: extending c++ to include type bool
  5. Date: 20 Apr 1996 00:22:59 GMT
  6. Organization: Netcom
  7. Message-ID: <01bb2e4f.c31ef2a0$d4c2b7c7@Zany.localhost>
  8. References: <bdsilver.829698454@extro> <3176C470.2647@cs.tu-berlin.de> <WALD.96Apr19094644@woodpecker.lcs.mit.edu>
  9. NNTP-Posting-Host: det-mi6-20.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 19  5:22:59 PM PDT 1996
  11. X-Newsreader: Microsoft Internet News
  12.  
  13.  
  14. On Friday, April 19, 1996, David Wald wrote...
  15. > In article <3176C470.2647@cs.tu-berlin.de> Roman Lechtchinsky
  16. > <wolfro@cs.tu-berlin.de> writes:
  17. > >Brett David Silverman wrote:
  18. > >> The question: Is it possible to create a class bool, in such a way
  19. > >> that it looks, smells, feels, talks, etc like the "real" bool?  To
  20. > >> the extent that I can create this class so that I am guaranteed
  21. > >> that the source will work, even though I can't see the source?
  22. > >I think one of the following should do ( depending on the compiler ):
  23. > >enum bool { false, true };
  24. > >or
  25. > >enum { false, true };
  26. > >typedef int bool;
  27. > (Didn't we just go through this?)  Thanks to overloading, it's not
  28. > possible for a user-defined type to completely emulate the C++ bool.
  29. > If you need a guarantee that some arbitrary code written with the C++
  30. > bool type will work with your user-defined type, you're out of luck.
  31. > Consider:
  32. >   int f(bool);
  33. >   int f(int);
  34. >   int g(int a, int b) { return f(a == b); }
  35. > In a system without built-in bool, no user-defined bool will result in
  36. > a call to f(bool).  You can't change the type of a built-in comparison
  37. > operator.
  38. > -David
  39.  
  40. I've tried creating bool substitutes; you can do a fairly good job if you
  41. create a class to mimic the behavior of bool as closely as possible as
  42. specified in the working papers available on AT&T's web site. The main
  43. problem you'll run into is the way overloading handles integral promotions
  44. at a higher priority than user-defined conversions (class conversion
  45. operators).
  46.  
  47. If you were *really* ambitious, you might be able to come up with an
  48. alternate preprocessor that reliably translates bools and bool expressions
  49. (including conditional and relational expressions). After all, that's how
  50. cfront works for the whole language. However, you might as well shell out
  51. $300ish for the real compiler from Borland, or wait for Microsoft to start
  52. supporting more of the draft standard.
  53.  
  54. Speaking of which... Microsoft has trouble making MFC compatible with just
  55. the STL. How are they going to cope with some of the tougher changes and
  56. not break MFC? Hmmm.
  57.  
  58. Bradd
  59.  
  60.  
  61.